package com.link2room.rodimus.service.impl;

import com.link2room.common.constant.DefaultValue;
import com.link2room.common.service.ICommonService;
import com.link2room.common.util.StringUtil;
import com.link2room.rodimus.entity.MemberLevelEntity;
import com.link2room.rodimus.constant.MemberConstant;
import com.link2room.rodimus.service.IMemberRankUtil;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * Created by LN on 2017/4/12.
 */
@Component("memberRankUtil")
public class MemberRankUtilImpl implements IMemberRankUtil {

    @Resource
    private ICommonService commonService;

    private final static String GC_CARD_0 = "0";
    private final static String GC_CARD_1 = "1";
    private final static String GC_CARD_2 = "2";
    private final static String GC_CARD_3 = "3";
    private final static String GC_CARD_A = "A";
    private final static String GC_CARD_A1 = "A1";
    private final static String GC_CARD_A2 = "A2";
    private final static String GC_CARD_A3 = "A3";
    private final static String GC_CARD_A4 = "A4";
    private final static String GC_CARD_B = "B";
    private final static String GC_CARD_C = "C";
    private final static String GC_CARD_D = "D";

    /**
     * 绿云等级转换到联房等级
     *
     * @param gcCardLevel
     * @return
     */
    @Override
    public String gcRank2L2RRank(String gcCardLevel) {
        String l2rLevel = null;
        if (StringUtil.isBlank(gcCardLevel)) {
            return l2rLevel;
        }
        if (gcCardLevel.equals(GC_CARD_0) || gcCardLevel.equals(GC_CARD_A) || gcCardLevel.equals(GC_CARD_A1)) {
            l2rLevel = MemberConstant.MEMBER_LEVEL.L0;
        } else if (gcCardLevel.equals(GC_CARD_1) || gcCardLevel.equals(GC_CARD_B) || gcCardLevel.equals(GC_CARD_A2)) {
            l2rLevel = MemberConstant.MEMBER_LEVEL.L1;
        } else if (gcCardLevel.equals(GC_CARD_2) || gcCardLevel.equals(GC_CARD_C) || gcCardLevel.equals(GC_CARD_A3)) {
            l2rLevel = MemberConstant.MEMBER_LEVEL.L2;
        } else if (gcCardLevel.equals(GC_CARD_3) || gcCardLevel.equals(GC_CARD_D) || gcCardLevel.equals(GC_CARD_A4)) {
            l2rLevel = MemberConstant.MEMBER_LEVEL.L3;
        }
        return l2rLevel;
    }

    @Override
    public String groupRankTOL2RRank(String lhotelGroupCode, String cardType, String cardLevel) throws Exception {
        MemberLevelEntity find = new MemberLevelEntity();
        find.setLhotelGroupCode(lhotelGroupCode);
        find.setCardLevel(cardLevel);
        find.setCardType(cardType);
        MemberLevelEntity qres = commonService.findOneEQ(MemberLevelEntity.class, find);
        if (qres != null) {
            return StringUtil.isNotBlank(qres.getL2RLevel()) ? qres.getL2RLevel() : DefaultValue.MEMBER_LEVEL;
        } else {
            return DefaultValue.MEMBER_LEVEL;
        }
    }
}
